package com.example.user.controller;


import com.example.user.common.Result;
import com.example.user.entity.ProductReview;
import com.example.user.request.ProductDetailInfoRequest;
import com.example.user.response.ProductDetailInfoResponse;
import com.example.user.service.ProductDetailInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "http://localhost:8080")
public class ProductDetailInfoController {

    @Autowired
    private ProductDetailInfoService productDetailInfoService;

    /**
     * 单个商品详情页
     */
//    @GetMapping("/getProductInfoDetail/{id}")
    @GetMapping("/getProductInfoDetail/{id}")
    public Result getProductInfoDetail(@PathVariable Integer id)
    {
       ProductDetailInfoResponse productDetailInfoResponse= productDetailInfoService.getProductInfoDetail(id);
       return Result.success(productDetailInfoResponse);
    }
    /**
     * 加入购物车
     */
    @PostMapping("/addCart")
    public Result addCart(@RequestBody ProductDetailInfoRequest productDetailInfoRequest){
        Result result=   productDetailInfoService.addCart(productDetailInfoRequest);
     return result;
    }

    /**
     * 收藏商品接口
     */

    @PostMapping("/collectShop")
    public Result collectShop(@RequestBody ProductDetailInfoRequest productDetailInfoRequest){
        Result result=   productDetailInfoService.collectShop(productDetailInfoRequest);
     return result;
    }

    /**
     * 商品评价列表展示
     */

    @GetMapping("/getProductComments/{productId}")
    public Result getReivews(@PathVariable Integer productId){
      //  int productId = productDetailInfoRequest.getProductId();
        //通过商品id进行查询
      Result result=  productDetailInfoService.getReivews(productId);
      return result;

      
    }

    /**
     * 提交评论接口
     */

    @PostMapping("/addComment")
    public Result addComment(@RequestBody ProductReview productReview){

      Result result= productDetailInfoService.addComment(productReview);
      return result;
    }





}
